home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
UTIL
/
Sleep Now 1.0.0.sit
/
Sleep Now 1.0.0
/
sleepnow.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-03-31
|
2KB
|
66 lines
/* Sleep Now was written by Geoffrey Keating, 31/3/1996. It is public domain. */
/* written for Universal Headers 2.1 */
#define SystemSevenOrLater 1
#define OLDROUTINENAMES 0
#define OLDROUTINELOCATIONS 0
#include <ControlStrip.h>
#include <Icons.h>
#include <Gestalt.h>
/* resource ID of the small icon we draw */
#define ourIconID 257
/* stuff to control the screen saver */
#define gestaltScreenSaverControl 'SAVC'
enum
{
eSaverWakeUp = 0,
eSaverSleep = 1,
eSaverOn = 2,
eSaverOff = 3
};
typedef short SaverCommand;
typedef pascal OSErr (*SaverControlProcPtr) (SaverCommand command);
/* the main (and only) routine for the sdev */
pascal long
main(long message, Handle iconSuite, Rect *statusRect, GrafPtr statusPort)
{
SaverControlProcPtr scp;
switch (message)
{
case sdevInitModule:
/* on init, we grab and save our icon */
if (SBGetDetachIconSuite(&iconSuite, ourIconID, kSelectorAllSmallData) == noErr)
return (long)iconSuite;
else
break;
case sdevCloseModule:
/* on close, we dispose the icon we got on startup */
if (iconSuite != NULL)
DisposeIconSuite(iconSuite, true);
break;
case sdevFeatures:
return 1<<sdevWantMouseClicks;
case sdevGetDisplayWidth:
return 16; /* width of our icon */
case sdevDrawStatus:
PlotIconSuite(statusRect, kAlignAbsoluteCenter, kTransformNone, iconSuite);
break;
case sdevMouseClick:
/* call the screen saver and tell it to sleep */
if (Gestalt(gestaltScreenSaverControl, (long *)&scp) == noErr &&
scp != NULL)
(*scp)(eSaverSleep);
else
/* if there is no screen saver, we're redundant, and should close. */
return 1<<sdevCloseNow;
break;
default:
break;
}
return 0;
}